package com.mxx.exceltoentity.ui;

import com.intellij.openapi.options.SearchableConfigurable;
import com.mxx.exceltoentity.util.SimpleConfigUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class SettingFactory implements SearchableConfigurable {

    private SettingUI settingUI = new SettingUI();

    @Override
    public @NotNull String getId() {
        return "excelToEntity.id";
    }

    @Override
    public @Nls(capitalization = Nls.Capitalization.Title) String getDisplayName() {
        return "Excel to Entity";
    }

    @Override
    public @Nullable JComponent createComponent() {
        return settingUI.getComponent();
    }

    @Override
    public boolean isModified() {
        return true;
    }

    @Override
    public void apply() {

        String appid = settingUI.getAppidField().getText();
        String secret = new String(settingUI.getPasswordField().getPassword());
        // 设置内容
        SimpleConfigUtil.save("key", appid);
        SimpleConfigUtil.save("value", secret);

    }

}